//引入mutations的常量
import { SET_CATEGORYLIST_STATE } from "../constant-type";

//引入api中的请求方法
import { reqCategoryList } from "@/api";

const state = {
    //三级分类列表
    categoryList: [],
};

const mutations = {
    //设置三级分类列表的值
    [SET_CATEGORYLIST_STATE](state, payload) {
        state.categoryList = payload.categoryList;
    },
};
const actions = {
    //异步获取三级分类列表的值
    async getCategoryList({ commit }) {
        try {
            const re = await reqCategoryList();
            commit(SET_CATEGORYLIST_STATE, { categoryList: re });
        } catch (e) {
            alert(e.message);
        }
    },
};
const getters = {};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters,
};
